package artid.com.arttogo.adapter;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import org.apache.commons.lang3.StringUtils;
import java.util.List;
import artid.com.arttogo.R;
import artid.com.arttogo.bean.ArtList;
import artid.com.arttogo.bean.AuctionLotListParser;
import artid.com.arttogo.utils.MyBitmapImageViewTarget;
import artid.com.arttogo.utils.NetUtils;
import artid.com.arttogo.view.CircleImageView;
import artid.com.arttogo.view.DynamicHeightImageView;

/**
 * 类描述： 主页-查询适配器
 * 创建人： 耿卫斌
 * 创建时间:2017/4/20 15:11
 */
public class MainQuery_Adapter extends BaseAdapter{
    private Context mContext;
    private List<ArtList> list;

    public MainQuery_Adapter(Context mContext, List<ArtList> list) {
        this.mContext = mContext;
        this.list = list;
    }

    public void notifyData(List<ArtList> list) {
        // TODO Auto-generated method stub
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        ViewHolder holder = null;
        View v = convertView;
        if (v == null) {
            holder = new ViewHolder();
            v = LayoutInflater.from(mContext).inflate(R.layout.item_mainquery, null);
            holder.img=(DynamicHeightImageView) v.findViewById(R.id.itemMainQuery_img);
            holder.describe=(TextView) v.findViewById(R.id.itemMainQuery_describe);
            holder.companyImg=(CircleImageView) v.findViewById(R.id.itemMainQuery_companyImg);
            holder.companyName=(TextView) v.findViewById(R.id.itemMainQuery_companyName);
            v.setTag(holder);
        } else {
            holder = (ViewHolder) v.getTag();
        }
        holder.img.setHeight(list.get(position).getHeight());
        Glide.with(mContext).load(list.get(position).getPic_url()
                + "_"+ (Integer.parseInt(NetUtils.getDisplayMetrics((Activity)mContext).get(NetUtils.DM_WIDTH)) /2) + "x10.png"
        ).asBitmap().placeholder(R.drawable.ic_menu_rotate).error(R.drawable.ic_menu_rotate).into(new MyBitmapImageViewTarget(holder.img));
        Glide.with(mContext).load(list.get(position).getPath()
                + "_"+ (Integer.parseInt(NetUtils.getDisplayMetrics((Activity)mContext).get(NetUtils.DM_WIDTH)) /2) + "x10.png"
        ).asBitmap().placeholder(R.drawable.ic_menu_rotate).error(R.drawable.ic_menu_rotate).into(new MyBitmapImageViewTarget(holder.companyImg));
        holder.describe.setText(StringUtils.substring(list.get(position).getTitle(),0,4));
        holder.companyName.setText(list.get(position).getRealname());
        return v;
    }
    class ViewHolder {
        DynamicHeightImageView img;
        CircleImageView companyImg;
        TextView describe,companyName;
    }
}
